<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>用户注册</title>
		<link rel="stylesheet" type="text/css" href="./css/login.css">
		<script src="js/jquery-3.5.1.js" type="application/javascript"></script>
		<script type="text/javascript">
			function clicksubmit() {
				var username = $("#username").val();
				var userpwd = $("#userpwd").val();
				var repwd=$("#repwd").val();
				alert(userpwd);
				alert(repwd);
				if (username == "") {
					$("#tip_username").html("用户名不能为空");
					return;
				} else if (userpwd == "") {
					$("#tip_username").html("");
					$("#tip_userpwd").html("密码不能为空");
					return;
				}else if(userpwd!=repwd){
					$("#tip_repwd").html("两次密码不一致")
					return;
				}
				else {
					$("#tip_username").html("");
					$("#tip_userpwd").html("");
				}

				var fileObj = document.getElementById("myfile").files[0]; // js 获取文件对象
				if (typeof (fileObj) == "undefined" || fileObj.size <= 0) {
					alert("请选择图片");
					return;
				}

				var formData = new FormData();
				formData.append("username", username);
				formData.append("userpwd", userpwd);
				formData.append("myfile", fileObj);

				$.ajax({
					type: "post",
					dataType: "json",
					url: "RegisterController",
					data: formData,
					cache: false,//上传文件无需缓存
					processData: false,//用于对data参数进行序列化处理 这里必须false
					contentType: false, //必须
					success: function (data, textStatus) {
						if (data.result == '1') {
							var url = "login";
							location.href = encodeURI(url + "?tip=注册成功，请登陆！！");
						} else {
							$("#tip").html("注册失败，请重新注册！！");
						}
					},
					error: function (msg) {
						alert("系统出现问题，请稍后注册！！！");
					}
				});
			}
		</script>
	</head>
	<body>


		<div class="regist">
			<div class="regist_center">
				<div class="regist_top">
					<div class="left fl">会员注册</div>
					<div class="right fr"><a href="index" target="_self">小米商城</a></div>
					<div class="clear"></div>
					<div class="xian center"></div>
				</div>
				<form  enctype="multipart/form-data" id="myform">
				<div class="regist_main center">
					<span id="tip"></span>
					<div class="username">用&nbsp;&nbsp;户&nbsp;&nbsp;名:&nbsp;&nbsp;<input class="shurukuang" id="username" type="text" name="username" placeholder="请输入你的用户名"/><span id="tip_username">请不要输入汉字</span></div>
					<div class="username">密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码:&nbsp;&nbsp;<input class="shurukuang" id="userpwd" type="password" name="userpwd" placeholder="请输入你的密码"/><span id="tip_userpwd">请输入6位以上字符</span></div>
					
					<div class="username">确认密码:&nbsp;&nbsp;<input class="shurukuang" id="repwd" type="password" name="repwd" placeholder="请确认你的密码"/><span id="tip_repwd">两次密码要输入一致哦</span></div>
					<div class="username">
						<div class="left fl">验&nbsp;&nbsp;证&nbsp;&nbsp;码:&nbsp;&nbsp;<input class="yanzhengma" type="text" name="yanzhengma" placeholder="请输入验证码"/></div>
						<div class="right fl"><img src="./image/yanzhengma.jpg"></div>
						<input id="myfile" name="myfile" type="file"/><br/>

						<div class="clear"></div>
					</div>
				</div>
				<div class="regist_submit">
					<input class="submit" type="button" name="submit" value="立即注册" onclick="clicksubmit()">
				</div>
				</form>
			</div>
		</div>

	</body>
</html>